package com.handmark.pulltorefresh.library.internal;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

import com.handmark.pulltorefresh.library.R;

public class PlanProgress extends View {

	private Context mContext;

	private static final int MAX_PROGRESS = 100;

	// 绘画类，设置绘图的样式和颜色。
	private Paint mPaint;

	private int progress = 0;

	private boolean isStrat = true;

	public void setProgress(int progress) {
		this.progress = progress;
	}

	public void setStrat(boolean isStrat) {
		this.isStrat = isStrat;
	}

	public PlanProgress(Context context, AttributeSet attrs, int defStyleAttr) {
		super(context, attrs, defStyleAttr);
		initData(context);
	}

	private void initData(Context context) {
		mContext = context;
		mPaint = new Paint();
		mPaint.setAntiAlias(true); // 抗锯齿
		mPaint.setColor(Color.BLACK);
		mPaint.setStyle(Paint.Style.FILL);
	}

	public PlanProgress(Context context, AttributeSet attrs) {
		super(context, attrs);
		initData(context);
	}

	public PlanProgress(Context context) {
		super(context);
		initData(context);
	}

	@Override
	protected void onDraw(Canvas canvas) {
//		if (isStrat) {
//			isStrat = false;
//			progress = 0;
//		}
		canvas.drawColor(mContext.getResources().getColor(R.color.colorPrimary));
		int max_height = canvas.getHeight();
		progress++;
		if(progress > 100){
			progress = 0;
		}
		int rect_height = progress * max_height / MAX_PROGRESS;
		RectF rect = new RectF(0, 0, canvas.getWidth(), max_height
				- rect_height);
		canvas.drawRect(rect, mPaint);
		invalidate(); // 重绘视图
	}
}
